﻿using System;

namespace Simp.Model
{
	/// <summary>Specifies the parameter policy of an expression.</summary>
	/// <remarks>We can't specify default values using this attribute.</remarks>
	[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
	public class ParameterPolicyAttribute : Attribute
	{
		private readonly IParameterBinding[] _parameterBindingList;

		/// <summary>Construct a policy by passing the parameter's names.</summary>
		/// <param name="parameterNameList"/>
		public ParameterPolicyAttribute(params string[] parameterNameList)
		{
			if (parameterNameList == null)
			{
				throw new ArgumentNullException("parameterNameList");
			}

			_parameterBindingList = ExpressionHelper.CreateParameterBinding(parameterNameList);
		}

		/// <summary>Construct a policy with a given number of parameters.</summary>
		/// <remarks>The parameter's names are automatically generated.</remarks>
		/// <param name="parameterCount"/>
		public ParameterPolicyAttribute(int parameterCount)
		{
			if (parameterCount < 0)
			{
				throw new ArgumentException("Can't be negative", "parameterCount");
			}

			_parameterBindingList = ExpressionHelper.CreateParameterBinding(parameterCount);
		}

		/// <summary>Returns the list of parameter bindings.</summary>
		public IParameterBinding[] ParameterBindings
		{
			get { return _parameterBindingList; }
		}
	}
}